package org.DragonPokerServer.Thread.ServerRequest;

import org.DragonPokerServer.dbclasses.User;
import org.Comunicator.Element;
import org.Comunicator.Global;
import org.Comunicator.Message;
import org.DragonPokerServer.Thread.ThreadUser;

/**
 *
 * @author davide
 */
public class LoginRequest extends GenericServerRequest{

    @Override
    public void processRequest(Message message, ThreadUser user) {
        System.out.println("SERVER-Login");
        String username = (String)message.getParameters().get("Username");
        String password = (String)message.getParameters().get("Password");

        User u = new User();
        u.setUsername(username);
        u.setPassword(password);
        user.setUser(u);
        //todo check if user exists
        Message reply = new Message();
        reply.setAction("LoginReply");
        reply.getReceiver().add(username);
        reply.getParameters().add(new Element("Reply", true));
        Global.messages.addMessageToSend(reply);
    }

    @Override
    public boolean isToProcessing(Message message, ThreadUser user) {
        //if(user.getUser() != null) return false;
        if("Login".equals(message.getAction()) == true)
            return true;
        else
            setNext(new RoomsRequest());
        return false;
    }

}
